#include "BuildEvent.h"

#include "BuildUnit.h"

namespace BroodWar
{
	namespace Addon
	{
		BuildEvent^ ConvertBuildEvent(BWSAL::BuildEvent* evt)
		{
			if(evt == NULL)
				return nullptr;
			return gcnew BuildEvent(evt);
		}

		BuildEvent^ ConvertBuildEvent(BWSAL::BuildEvent evt)
		{
			return gcnew BuildEvent(evt);
		}

		BWSAL::BuildEvent ConvertBuildEvent(BuildEvent^ evt)
		{
			return BWSAL::BuildEvent(*(evt->instance));
		}

		BuildEvent::BuildEvent(BWSAL::BuildEvent* evt)
		{
			instance = evt;
			dispose = false;
		}

		BuildEvent::BuildEvent(BWSAL::BuildEvent evt)
		{
			instance = new BWSAL::BuildEvent(evt);
			dispose = true;
		}

		BuildEvent::~BuildEvent()
		{
			if(dispose)
				delete instance;
		}

		BuildEvent::!BuildEvent()
		{
			if(dispose)
				delete instance;
		}

		BuildEvent::BuildEvent(Addon::BuildType buildType, int deltaMinerals, int deltaGas, int deltaSupply)
		{
			instance = new BWSAL::BuildEvent(ConvertBuild(buildType), deltaMinerals, deltaGas, deltaSupply);
			dispose = true;
		}
		
		BuildEvent::BuildEvent(Addon::BuildType buildType, int deltaMinerals, int deltaGas)
		{
			instance = new BWSAL::BuildEvent(ConvertBuild(buildType), deltaMinerals, deltaGas);
			dispose = true;
		}
		
		BuildEvent::BuildEvent(Addon::BuildType buildType, int deltaMinerals)
		{
			instance = new BWSAL::BuildEvent(ConvertBuild(buildType), deltaMinerals);
			dispose = true;
		}
		
		BuildEvent::BuildEvent(Addon::BuildType buildType)
		{
			instance = new BWSAL::BuildEvent(ConvertBuild(buildType));
			dispose = true;
		}

		void BuildEvent::Set(Addon::BuildType buildType, int deltaMinerals, int deltaGas, int deltaSupply)
		{
			instance->set(ConvertBuild(buildType), deltaMinerals, deltaGas, deltaSupply);
		}
		
		BuildEvent^ BuildEvent::SetBuildUnitUnavailable(Addon::BuildType type, BuildUnit^ unit)
		{
			return ConvertBuildEvent(instance->setBuildUnitUnavailable(ConvertBuild(type), ConvertBuildUnit(unit)));
		}
		
		BuildEvent^ BuildEvent::SetBuildUnitAvailable(Addon::BuildType type, BuildUnit^ unit)
		{
			return ConvertBuildEvent(instance->setBuildUnitAvailable(ConvertBuild(type), ConvertBuildUnit(unit)));
		}
		
		BuildEvent^ BuildEvent::SetCompletedBuildType(Addon::BuildType type)
		{
			return ConvertBuildEvent(instance->setCompletedBuildType(ConvertBuild(type)));
		}
		
		BuildEvent^ BuildEvent::UseLarva(BuildUnit^ unit)
		{
			return ConvertBuildEvent(instance->useLarva(ConvertBuildUnit(unit)));
		}
		
		BuildEvent^ BuildEvent::SetAddon(BuildUnit^ unit)
		{
			return ConvertBuildEvent(instance->setAddon(ConvertBuildUnit(unit)));
		}
		
		Build^ BuildEvent::BuildType::get()
		{
			return ConvertBuild(instance->getBuildType());
		}
		
		int BuildEvent::DeltaMinerals::get()
		{
			return instance->getDeltaMinerals();
		}
		
		int BuildEvent::DeltaGas::get()
		{
			return instance->getDeltaGas();
		}
		
		int BuildEvent::DeltaSupply::get()
		{
			return instance->getDeltaSupply();
		}
		
		BuildUnit^ BuildEvent::UsesLarva::get()
		{
			return ConvertBuildUnit(instance->getUseLarva());
		}

		String^ BuildEvent::ToString()
		{
			return gcnew String(instance->toString().c_str());
		}
	}
}
